package weixinkeji.dev.dc.buy.order.h.fwy;

import sys.wx.ann.hm.M;
import sys.wx.ann.power.head.SQ;
import sys.wx.c.ATR;
import sys.wx.c.components.check.bean.CheckData;
import sys.wx.c.components.cv.CV;
import sys.wx.m.db.SQL.mysql.SQLI;
import sys.wx.m.db.SQL.mysql.bean.SQLADD;
import sys.wx.m.db.SQL.mysql.common.where.Where;
import sys.wx.m.db.dao.mysql.Dao;
import weixinkeji.dev.dc.DCPower;
import weixinkeji.dev.dc.base.refectory.bean.Refectory;
import weixinkeji.dev.dc.buy.order.bean.FWYOrder;
import weixinkeji.dev.dc.buy.order.h.fwy.vo.VOTool;

@sys.wx.ann.hm.H("view/buy/order/fwy/a")

//身份类型授权。无需人工付权。
//代表 是服务员才能进行访问。
@SQ(DCPower.ID_FWY)
public class FWYKDHA {

    @M("/add")//通过 view/buy/order/fwy/a/add.imy 访问
    public static String add(ATR a) {
        String refectory_code = CV.getParameter(a.request, "refectory_code", CheckData.NUMBER_INT_L + "{1,26}");
        if (null == refectory_code) {
            a.printOne("餐点不合规则！");
            return null;
        }

        Refectory rf = Dao.selectOneByTJ(Refectory.class, Where.putThenGet(Where.TJ_IGNORE_NOTHING, null, "", "refectory_code", "=", refectory_code));
        if (null == rf.getRefectory_id()) {
            a.printOne("餐点不存在！");
            return null;
        }
        SQLADD saObj = SQLI.insert_SQLADD(VOTool.getFWYOrder(a, rf));
        a.printOne(Dao.executeUpdate(saObj.sql) ? saObj.id : "开单失败！");
        return null;
    }

}
